package com.mikey.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @author :Mikey
 * @description :8锁，就是关于锁的8个问题
 * 1，synchronized锁的是对象方法的调用者，谁先拿到谁就使用
 * 2，，，，，
 * @create :2022-09-20 15:09:00
 */
public class Test {
    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(()->{
            phone.sendMsg();
        },"A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(()->{
            phone.call();
        },"B").start();
    }
}
class Phone{
    public synchronized void sendMsg(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }
    public  synchronized void call(){
        System.out.println("打电话");
    }
}